<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- <meta http-equiv="refresh" content="10"> -->
<title>美丽敲敲门大地图</title>
<style type="text/css">
html {
	height: 100%
}

body {
	height: 100%;
	margin: 0px;
	padding: 0px
}

#container {
	height: 100%
}
</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=DDbl4GuGNmDrLbKeaDsCzAeDfOGhdyET">
	//v2.0版本的引用方式：src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
	//v1.4版本及以前版本的引用方式：src="http://api.map.baidu.com/api?v=1.4&key=您的密钥&callback=initialize"
</script>
</head>
<script language="javascript">
	var XMLHttpReq;
	//创建XMLHttpRequest对象         
	function createXMLHttpRequest() {
		if (window.XMLHttpRequest) { //Mozilla 浏览器  
			XMLHttpReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE浏览器  
			try {
				XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				}
			}
		}
	}
	var XMLHttpReqb;
	//创建XMLHttpRequest对象         
	function createXMLHttpRequestb() {
		if (window.XMLHttpRequest) { //Mozilla 浏览器  
			XMLHttpReqb = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE浏览器  
			try {
				XMLHttpReqb = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReqb = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				}
			}
		}
	}
</script>
<body>
	<div id="container">
		<div id="show" style="background-color: white;">guochaolang</div>
	</div>
	
	<script type="text/javascript">
		var map = new BMap.Map("container"); // 创建地图实例  
		map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
		var point = new BMap.Point(115.851808, 28.694773); // 创建点坐标  
		var point2 = new BMap.Point(115.86999, 28.687675);

		map.centerAndZoom(point, 15); // 初始化地图，设置中心点坐标和地图级别

		var mapPoints;
		//查询按钮
		function search() {
			sendRequest();
		}

		//发送请求函数  
		function sendRequest() {
			createXMLHttpRequest();
			var url = window.location.protocol + "/mlqm/map/getlocation";
			//var url = "http://139.196.112.42/mlqm/map/getlocation";
			XMLHttpReq.open("GET", url, true);
			XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
			XMLHttpReq.send(null); // 发送请求  
		}

		// 处理返回信息函数  
		function processResponse() {
			if (XMLHttpReq.readyState == 4) { // 判断对象状态  
				if (XMLHttpReq.status == 200) { // 信息已经成功返回，开始处理信息
					DisplayHot();
					//setTimeout("sendRequest()", 1000);
				} else { //页面不正常  
					window.alert("您所请求的页面有异常。");
				}
			}
		}//

		function DisplayHot() {
			var r = XMLHttpReq.responseText;
			if (r == "") {
				alert("未查找到！！！");
			} else {
				//var obj = eval(r);
				var obj = JSON.parse(r);
				var data = obj.data;
				//alert(data);
				mapPoints = data;
				var baseurl = window.location.protocol;
				for (var i = 0; i < mapPoints.length; i++) {
					if (mapPoints[i].type == "2") {
						//技师
						baseurl = window.location.protocol
								+ "/mMaps/images/webjishi.png";
						var tmp_point = new BMap.Point(mapPoints[i].longitude,
								mapPoints[i].latitude); // 创建点坐标
						//alert(mapPoints[i].longitude + ","+ mapPoints[i].latitude);
						var myIcon = new BMap.Icon(baseurl, new BMap.Size(40,
								150));
						var tmp_marker = new BMap.Marker(tmp_point, {
							icon : myIcon
						}); // 创建标注        
						var label = new BMap.Label("技师" + mapPoints[i].id, {
							offset : new BMap.Size(-15, -20)
						});
						//alert(baseurl);
						tmp_marker.setLabel(label);
						map.addOverlay(tmp_marker); // 将标注添加到地图中
					} else {
						//客户
						//alert(mapPoints[i].longitude + ","+ mapPoints[i].latitude);
						/* baseurl = window.location.protocol
								+ "/mMaps/images/webkehu.png";
						var tmp_point = new BMap.Point(mapPoints[i].longitude,
								mapPoints[i].latitude); // 创建点坐标
						var myIcon = new BMap.Icon(baseurl, new BMap.Size(40,
								150));
						var tmp_marker = new BMap.Marker(tmp_point, {
							icon : myIcon
						}); // 创建标注 
						var label = new BMap.Label("客户" + mapPoints[i].id, {
							offset : new BMap.Size(-15, -20)
						});
						tmp_marker.setLabel(label);
						map.addOverlay(tmp_marker); // 将标注添加到地图中  */
					}
				}
			}
		}

		var mapPointsb;
		//查询用户技师位置 订单
		function search_b() {
			sendRequest_b();
		}

		//发送请求函数  
		function sendRequest_b() {
			createXMLHttpRequestb();
			var url = window.location.protocol + "/mlqm/map/getbilllocation";
			XMLHttpReqb.open("GET", url, true);
			XMLHttpReqb.onreadystatechange = processResponse_b;//指定响应函数  
			XMLHttpReqb.send(null); // 发送请求  
		}

		// 处理返回信息函数  
		function processResponse_b() {
			if (XMLHttpReqb.readyState == 4) { // 判断对象状态  
				if (XMLHttpReqb.status == 200) { // 信息已经成功返回，开始处理信息
					DisplayHot_b();
					//setTimeout("sendRequest()", 1000);
				} else { //页面不正常
					window.alert("您所请求的页面有异常。");
				}
			}
		}//

		function DisplayHot_b() {
			var r = XMLHttpReqb.responseText;
			if (r == "") {
				alert("未查找到！！！");
			} else {
				var obj = JSON.parse(r);
				var data = obj.data;
				mapPointsb = data;
				var baseurl = window.location.protocol;
				for (var i = 0; i < mapPointsb.length; i++) {
					//alert(mapPoints[i].j_longitude+","+mapPoints[i].j_latitude);
					var start = new BMap.Point(mapPointsb[i].j_longitude,
							mapPointsb[i].j_latitude); // 创建点坐标
					var end = new BMap.Point(mapPointsb[i].c_longitude,
							mapPointsb[i].c_latitude); // 创建点坐标
					//用户标注
					var baseeurl = window.location.protocol
							+ "/mMaps/images/webkehu.png";
					var myIcon = new BMap.Icon(baseeurl, new BMap.Size(40, 150));
					var tmp_marker = new BMap.Marker(end, {
						icon : myIcon
					}); // 创建标注 
					var label = new BMap.Label("客户" + mapPointsb[i].id, {
						offset : new BMap.Size(-15, -20)
					});
					tmp_marker.setLabel(label);
					map.addOverlay(tmp_marker); // 将标注添加到地图中

					//绘制弧线
					//var points = [start,end];
					//var curve = new BMapLib.CurveLine(points, {strokeColor:"blue", strokeWeight:3, strokeOpacity:0.5}); //创建弧线对象
					//map.addOverlay(curve); //添加到地图中
					//绘制直线
					/* var polyline = new BMap.Polyline([ start, end ], {
						strokeColor : "red",//设置颜色 
						strokeWeight : 3, //宽度
						strokeOpacity : 0.5
					});//透明度
					map.addOverlay(polyline); */

					//alert(mapPoints.id);
					//公交
					//var transit = new BMap.TransitRoute(map, {
					//	renderOptions : {
					//		map : map
					//	}
					//});
					//transit.search(start, end);
					//驾车
					/* var driving = new BMap.DrivingRoute(map, {
						renderOptions : {
							map : map,
							//autoViewport : true
						}
					});
					driving.search(start, end); */

					//步行
					var walking = new BMap.WalkingRoute(map, {
						renderOptions : {
							map : map,
						//autoViewport : true
						}
					});
					walking.search(start, end);

					/* baseurl = window.location.protocol
							+ "/mMaps/images/start.png";
					//alert(mapPoints[i].longitude + ","+ mapPoints[i].latitude);
					var myIcon = new BMap.Icon(baseurl, new BMap.Size(40, 150));
					var start_marker = new BMap.Marker(start, {
						icon : myIcon
					}); // 创建标注        
					var label = new BMap.Label("起始位置" + mapPoints[i].id, {
						offset : new BMap.Size(-15, -20)
					});
					//alert(baseurl);
					start_marker.setLabel(label);
					map.addOverlay(start_marker); // 将标注添加到地图中
					baseurl = window.location.protocol
					+ "/mMaps/images/end.png";
					myIcon = new BMap.Icon(baseurl, new BMap.Size(40, 150));
					var end_marker = new BMap.Marker(start, {
						icon : myIcon
					}); // 创建标注        
					label = new BMap.Label("起始位置" + mapPoints[i].id, {
						offset : new BMap.Size(-15, -20)
					});
					//alert(baseurl);
					end_marker.setLabel(label);
					map.addOverlay(end_marker); // 将标注添加到地图中 */
				}
			}
		}

		search();
		search_b();
		//setTimeout(doLocation(),5000);
		setInterval(function() {
			doLocation();
		}, 10000);
		function doLocation() {
			//map.clearOver();
			map.clearOverlays();
			search();
			search_b();
		}
	</script>
</body>
</html>